package foti;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class validate
 */
@WebServlet("/validate")
public class validate extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public validate() {
        super();
       
    }


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		String vuser = request.getParameter("user");
		String vpass = request.getParameter("pass");
		
		if (vuser == null || vpass == null){
			out.println("Please fill out the form.");
			return;
		}
		
		if (vuser.equals("foti") && vpass.equals("entjava")){
			out.println("Login is correct.");
			
			RequestDispatcher main = request.getRequestDispatcher("toc");
			main.forward(request,response);
			
			
			
			return;
		}
		else {
			out.println("Login is incorrect." +
						"<br>Please enter the correct username and password.");
		}
		
		out.println("Username: " + vuser.toLowerCase() + 
				"	|	Password: " + vpass.toLowerCase());
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
